#include <iostream>
#include <vector>
/*
int Check(std::vector<int>& v)
{
    int ret = 0;
    for(int max = v.size() - 1; max > 1; max--)
    {
        int left = 0, right = max - 1;
        while(left < right)
        {
            if(v[left] + v[right] <= v[max])
            {
                left++;
            }
            else
            {
                ret += right - left;
                right--;
            }
        }
    }
    return ret;
}

int checkPractice(std::vector<int>& v)
{
    int ret = 0;
    int max = v.size() - 1;
    int left = 0, right = max - 1;
    while(left < right)
    {
        if(v[left] + v[right] <= v[max])
        {
            left++;
        }
        else
        {
            ret += right - left;
            right--;
        }
    }
    return ret;
}

int main()
{
    std::vector<int> v = {2, 2, 3, 4};
    std::sort(v.begin(), v.end());
    std::cout << Check(v) << std::endl;
    return 0;
}
*/

int Check(std::vector<int>& v)
{
    std::sort(v.begin(), v.end());
    int ret = 0, n = v.size();
    for(int max = n - 1; max >= 2; max--)
    {
        int left = 0;
        int right = max - 1;
        while(left < right)
        {
            if(v[left] + v[right] > v[max])
            {
                ret += right - left;
                right--;
            }
            else
            {
                left++;
            }
        }
    }
    return ret;
}

int main()
{
    std::vector<int> v = {2, 2, 3, 4};
    std::random_shuffle(v.begin(), v.end());
    std::cout << Check(v) << std::endl;

    std::vector<int>::iterator it = v.begin();
    while(it != v.end())
    {
        std::cout << *it << std::endl;
        it++;
    }
    return 0;
}